home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Interactive Web Graphics with Shout 3D
/
Interactive Web Graphics With Shout 3D.iso
/
pc
/
Shout3Ddemo
/
Shout3d_runtime
/
codebase
/
custom_nodes
/
InvertPlusOverlayTextEffect.jav
< prev
next >
Wrap
Text File
|
2000-09-21
|
3KB
|
88 lines
/**
Company: Eyematic Interfaces
Project: Shout3D Core
Class: TestEffect
Date: March 23, 2000
Description: A simple example of a PostRenderEffect that inverts the colors of the scene and adds some text on top.
(C) Copyright Eyematic Interfaces, Inc. - 1997/1998/1999/2000 - All rights reserved
*/
package custom_nodes;
import shout3d.core.*;
import shout3d.*;
import shout3d.core.awt.*;
import java.awt.*;
import java.awt.image.*;
/**
* TestEffect
*
* @author Dave Westwood
*/
public class InvertPlusOverlayTextEffect extends PostRenderEffect{
/**
* Constructs a default InvertPlusOverlayTextEffect node.
*/
public InvertPlusOverlayTextEffect(){}
int[] defaultStartPosition = { 160, 0 };
int[] defaultTextVelocity = { 0, 10 };
final public BooleanField invertEnabled = new BooleanField(this, "invertEnabled", Field.ANY, true);
final public StringField overlayText = new StringField(this, "overlayText", Field.ANY, "WAZZUP!");
final public IntArrayField startPosition = new IntArrayField(this, "startPosition", Field.ANY, defaultStartPosition);
final public IntArrayField textVelocity = new IntArrayField(this, "textVelocity", Field.ANY, defaultTextVelocity);
Font bigFont = new Font("Arial", Font.BOLD, 30);
int x, y = 0;
int xVelo = 0;
int yVelo = 10;
boolean firstTime = true;
public void filter(Graphics g, int surface_pixel_bits[], float z_buffer[], int deviceWidth, int deviceHeight){
if (surface_pixel_bits == null)
return;
// Invert
if (invertEnabled.getValue()){
for (int i=0;i<surface_pixel_bits.length;i++){
surface_pixel_bits[i] = 0xff000000 +
((255-((surface_pixel_bits[i]>>16)&0xff))<<16) + // invert red
((255-((surface_pixel_bits[i]>>8)&0xff))<<8) + // invert green
((255-((surface_pixel_bits[i])&0xff))); // invert blue
}
}
// initialize position and velocity
if (firstTime && startPosition.getValue() != null && startPosition.getValue().length > 1){
x = startPosition.getValue()[0];
y = startPosition.getValue()[1];
}
if (firstTime && textVelocity.getValue() != null && textVelocity.getValue().length > 1){
xVelo = textVelocity.getValue()[0];
yVelo = textVelocity.getValue()[1];
}
firstTime = false;
// Draw some text
g.setFont(bigFont);
g.setColor(java.awt.Color.green);
if (x > deviceWidth)
x = 0;
else if (x < 0)
x = deviceWidth;
else
x+= xVelo;
if (y > deviceHeight)
y = 0;
else if (y < 0)
y = deviceHeight;
else
y+= yVelo;
g.drawString(overlayText.getValue(), x, y);
}
}